package cn.swenty.backstage.framework.common.tree;

import java.util.List;
import java.util.Map;

public class TreeNodeModel implements TreeNode, Comparable<TreeNode> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String id;

	private String name;

	private String parentName;

	private String parentId;

	private Integer displayNo = 0;

	private TreeNode parent;

	private List<TreeNode> children;

	public String getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public String getParentName() {
		return parentName;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	public Integer getDisplayNo() {
		return displayNo;
	}

	
	public void setDisplayNo(Integer displayNo) {
		this.displayNo = displayNo;
	}

	
	public List getChildren() {
		return children;
	}

	
	public void setChildren(List nodes) {
		this.children = nodes;
	}

	
	public void setParent(TreeNode parent) {
		this.parent = parent;
	}

	
	public TreeNode getParent() {
		return parent;
	}

	
	public Map<String, Object> filter() {
		return null;
	}

	
	public int compareTo(TreeNode arg0) {
		return this.displayNo = arg0.getDisplayNo();
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setParentName(String parentName) {
		this.parentName = parentName;
	}

	public static TreeNodeModel create(String id, String parentId, String name, int display) {
		TreeNodeModel nodeModel = new TreeNodeModel();
		nodeModel.setId(id);
		nodeModel.setName(name);
		nodeModel.setParentId(parentId);
		nodeModel.setDisplayNo(display);
		return nodeModel;
	}

	public static boolean isExistNode(List<TreeNode> nodes, String id) {

		if (nodes != null) {
			for (TreeNode treeNode : nodes) {
				if (treeNode.getId().equals(id)) {
					return true;
				}else{
					isExistNode(treeNode.getChildren(), id);
				}
			}
		}
		return false;
	}

}
